﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AddMarginConverter.cs" company="http://buginbox.wordpress.com/">
//   Copyright (c) GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Windows.Data;

namespace Wpf.Core.Converter
{
    /// <summary>
    /// The add margin converter.
    /// </summary>
    [ValueConversion(typeof(decimal), typeof(decimal))]
    public class AddMarginConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="value">
        /// The value. 
        /// </param>
        /// <param name="targetType">
        /// The target type. 
        /// </param>
        /// <param name="parameter">
        /// The parameter. 
        /// </param>
        /// <param name="culture">
        /// The culture. 
        /// </param>
        /// <returns>
        /// The convert 
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// InvalidOperationException
        /// </exception>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(double))
            {
                throw new InvalidOperationException("The target must be a double");
            }

            return (double)value + double.Parse((string)parameter);
        }

        /// <summary>
        /// The convert back.
        /// </summary>
        /// <param name="value">
        /// The value. 
        /// </param>
        /// <param name="targetType">
        /// The target type. 
        /// </param>
        /// <param name="parameter">
        /// The parameter. 
        /// </param>
        /// <param name="culture">
        /// The culture. 
        /// </param>
        /// <returns>
        /// The convert back 
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// NotSupportedException
        /// </exception>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}